//---------------------------------------------------------------------------- // File: C3DVertices.cpp // Class: C3DVertices [v5] -- Common 3D Universal Class // Type: 3D Object // Author: Ken Anderson // Date: 1/29/06 // OS dependant: NA // Desc: A class designated to manage a block of vertices and it's corresponding // textures. During the creation process the C3DVertices class calls the // VertexBank to assign it a handle to the current block of vertices. // // Notes: The VertexBank manages a link or handle to the original block of data // as well as data that is specific to the renderer. // // Note2: Due to a loss of a newer version of data, stricter version control // is being implemented. // // Required headers: // 1) C3DVertices.h -- Required to access its own class. //---------------------------------------------------------------------------- #include "C3DVertices.h" /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Constructor [v5.0] // Overridden: NA // Permission: Private // Date: 1/29/06 // Type: Common 3D Object. // Desc: Initializes member variables. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DVertices::C3DVertices() { m_pVertices = NULL; //Set the vertex pipeline to null. m_hCallback = NULL; //Set the HRBE (Handle to Render Bank Element) callback to null. //Assigns the current position to not existing, //each vertex function should inc automatically. m_dwCurrVertPos = -1; m_bHold = false; //disable holding. } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Destructor [v5.0] // Overridden: NA // Permission: Private // Date: 1/29/06 // Type: Common 3D Object. // Desc: Cleans up member variables. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DVertices::~C3DVertices() { Cleanup(); //Purge the vertex pipeline. SDELETE(m_pVertices); //Delete the vertex block. } ///////////////////////////////////////////////////// //---------------------/// PRIVATE MEMBERS ///------------------------// ///////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: ZeroVertexElement [v5.0] // Overridden: NA // Permission: Private // Date: 1/29/06 // Type: Common 3D Object. // Desc: Zeros initializes the vertex element. // Parameters: // 1) PSC3DVertex pElement == Vertex element to zero. // 2) Byte byVType == Vertex type being used. 0 for v3 and 1 for v4. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::ZeroVertexElement(PSC3DVertex pElement, Byte byVType) { //Return creation error. if(pElement == NULL) return; //Local variables. int c; //Zero members. if(byVType == 0) pElement->v3.x = pElement->v3.y = pElement->v3.z = 0.0f; else if(byVType == 1) pElement->v4.x = pElement->v4.y = pElement->v4.z = pElement->v4.rhw = 0.0f; pElement->n.x = pElement->n.y = pElement->n.z = 0.0f; pElement->dwDiffuse = 0x00000000; pElement->dwSpecular = 0x00000000; for(c = 0;c < MAXTEXTURES; c++) pElement->t[c].x = pElement->t[c].y = 0.0f; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: ReturnVertexElement [v5.0] // Overridden: NA // Permission: Private // Date: 1/30/06 // Type: Common 3D Object. // Desc: Returns a vertex element specified in the index parameter. // Parameters: // 1) Dword dwIndex == The index or position in the vertex table to return. // Return value: None // PSC3DVertex == A pointer to the vertex element in the Vertex array table. // If the index selected is out of range or the table is null // then a null value will be returned. ////////////////////////////////////////////////////////////////////////////////////////////////////// PSC3DVertex C3DVertices::ReturnVertexElement(Dword dwIndex) { //Vertex index supplied is out of range. if((dwIndex < 0) || (dwIndex > (m_pVertices->dwVertnum-1))) return NULL; //Return the direct memory address of the element. return &(m_pVertices->pVArray[dwIndex]); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: UpdateVertexBank // Overridden: NA // Permission: Private // Date: 9/30/04 // Type: Common 3D Object. // Desc: Updates the vertex bank by sending the data in the pV parameter to the bank // and returning a callback handle. // Parameters: // 1) PSC3DVertices pV == A pointer to a Common 3D Vertices Structure that is to be added to the bank. // 2) TRBE trbe == A triset used to return a valid Handle to a Render Bank Element. // Null and the error status is returned if the update fails. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::UpdateVertexBank(PSC3DVertices pV, TRBE trbe) { //Locals C3DRenderBank* m_pVertexBank; //A pointer to the current vertex bank. HRBE hCallback = NULL; BANKERR err=BK_OK; //Returns a null parameter. if(trbe == NULL) return ECERR_NULL; //Fetch the current vertex bank. m_pVertexBank = ReturnVertexBank(); //Send vertices data to the vertex bank as long as the vertex bank is not invalid. if(m_pVertexBank != NULL) { err = m_pVertexBank->AllocateSlot(&hCallback); //Create a slot & return the callback. //Check the error status. if(!err) { if(hCallback != NULL) { if(*hCallback != NULL) { (*hCallback)->p3DObject = pV; //Assign an object to the callback. (*hCallback)->rbsState = BSV_NEW; //Notify the renderbank that the 3d object data is new. (*hCallback)->pNext = NULL; //The next pointer should be null. //Assign the callback to the triset. *trbe = hCallback; } else return C3DERR_RBENULL; } else return C3DERR_RBENULL; } else if(err == BKERR_NOTCREATE) return C3DERR_NOINITBANK; else if(err == BKERR_OUTOFMEM) return C3DERR_OUTOFMEM; else return C3DERR_UNKNOWN; } else return C3DERR_NOINITBANK; return C3D_OK; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: RefreshVertexBank [v2.2] // Overridden: NA // Permission: Private // Date: 9/30/04 // Type: Common 3D Object. // Desc: This private function signals the renderer to refresh the state of the object. // Parameters: // 1) C3DRenderBankStates rbs == A Render bank state that maybe different from a refresh. // By default the render bank state is set to refresh. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::RefreshVertexBank(C3DRenderBankStates rbs) { //Notify the render bank to refresh the coordinates of the vertices. //Note that the BSV_NEW & BSV_UPDATE flags get the highest priorities //and will not allow refresh or render to replace the rbs. if(!m_bHold) //[v2.2] Update -- Do not refresh unless the hold is disabled. if(m_hCallback != NULL) if(*m_hCallback != NULL) if((*m_hCallback)->rbsState != BSV_NEW) if((*m_hCallback)->rbsState != BSV_UPDATE) (*m_hCallback)->rbsState = rbs; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Cleanup [v5.0] // Overridden: NA // Permission: Private // Date: 1/29/06 // Type: Common 3D Object. // Desc: Cleans up the vertex pipeline. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Cleanup() { //Locals C3DRenderBank* m_pVertexBank; //Check for null vertices. if(m_pVertices == NULL) return; //Confirm the array is valid. if(m_pVertices->pVArray == NULL) return; //Destroy the array. SDELETE(m_pVertices->pVArray); //Disable any rendering of an empty pipeline. m_pVertices->bEnabled = false; m_pVertices->dwVertnum = 0; m_pVertices->byStage = 0; m_pVertexBank = ReturnVertexBank(); //Remove the slot in the vertex bank. if(m_pVertexBank != NULL) { //Notify the bank to clean the element up if it is still //active during the deallocate slot process. if(m_hCallback != NULL) { if(*m_hCallback != NULL) { (*m_hCallback)->p3DObject = NULL; (*m_hCallback)->rbsState = BSV_DESTROY; //Updated 4/13/05 -- System now uses a direct access method to the //destroy unused objects immediately. if(g_pCRSManager != NULL) if(g_pCRSManager->m_pC3D != NULL) g_pCRSManager->m_pC3D->DestroyVertexBuffer(m_hCallback); } } } } ///////////////////////////////////////////////////// //---------------------/// PUBLIC MEMBERS ///------------------------// ///////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Create [v5.0] // Overridden: NA // Permission: Public // Date: 1/29/06 // Type: Common 3D Object. // Desc: Internally creates the vertex block that holds all the vertices information. // Parameters: // 1) Dword dwNumVertices == A value that represents the amount of vertices to create. // By default uses 500 vertices if not specified. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Create(Dword dwNumVertices) { //Locals PSC3DVertex pElements = NULL; C3DERR err=C3D_OK; //If the vertices block has already been created, ignore the //creation process. if(m_pVertices != NULL) return C3D_OK; //Allocate memory for a vertices block, //and return out of memory errcode if failed. if((m_pVertices = new SC3DVertices) == NULL) return C3DERR_OUTOFMEM; //Allocate memory for the array of vertices. if((pElements = new SC3DVertex[dwNumVertices]) == NULL) return C3DERR_OUTOFMEM; m_pVertices->pVArray = pElements; //Assign the array of vertices to the block. m_pVertices->dwVertnum= dwNumVertices; m_pVertices->dwNumRend = dwNumVertices; //Number of vertices to render. //Init the vertices block. m_pVertices->bEnabled = true; //By default enable it for rendering. m_pVertices->pt = C3DPT_POINTLIST; //The type of rendering performed on vertices. m_pVertices->dwStartRend = 0; //Starting position of the vertex to render. m_pVertices->wUsage = 0; //Usage not defined yet. //Update the Vertex bank. //If an error occurs, report it and clean up the vertices. if(FAIL(err = UpdateVertexBank(m_pVertices, &m_hCallback))) { SDELETE(pElements); SDELETE(m_pVertices); return err; } //return errors: By default returns okay. return C3D_OK; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: DeleteVertices *Untested* // Overridden: NA // Permission: Public // Date: 3/15/4 // Type: Common 3D System Management. // Desc: Cleans up the vertex pipeline for the user, resetting the object to a clean one, yet maintatins // the memory for the vertex block to hold the vertex pipeline. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Clear() { Cleanup(); //Purge vertex pipeline. } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: SetPrimitiveType [v2.3] // Overridden: NA // Permission: Public // Date: 5/5/05 // Type: Common 3D System Management. // *Tested: 4/28/05 // Desc: Sets the type of primitive to render. // Parameters: // 1) C3DPrimitiveType PrimType = Method of drawing the vertexblock. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::SetPrimitiveType(C3DPrimitiveType PrimType) { if(m_pVertices != NULL) { m_pVertices->pt = PrimType; return C3D_OK; } else return C3DERR_NACREATE; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: GetPrimitiveType [v2.3] // Overridden: NA // Permission: Public // Date: 5/5/05 // Type: Common 3D System Management. // Tested: // Desc: Returns the type of primitive to render. // A null vertices block returns null. // Parameters: None // Return value: // C3DPrimitiveType PrimType = Method of drawing the vrtexblock.e ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DPrimitiveType C3DVertices::GetPrimitiveType() { if(m_pVertices == NULL) return C3DPT_UNKNOWN; else return m_pVertices->pt; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Enable [v2.3] // Overridden: NA // Permission: Public // Date: 5/5/05 // Type: Common 3D System Management. // Tested: // Desc: Enables the vertices object. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Enable() { if(m_pVertices != NULL) m_pVertices->bEnabled = true; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Disable [v2.3] // Overridden: NA // Permission: Public // Date: 5/5/05 // Type: Common 3D System Management. // Tested: // Desc: Disables the vertices object. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Disable() { if(m_pVertices != NULL) m_pVertices->bEnabled = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Render // Overridden: NA // Permission: Public // Date: 10/11/04 // Type: Common 3D System Management. // Desc: Performs a rendering of the vertices block according to the parameters that were provided. // Parameters: // 1) Byte byStage == The stage to render the block of vertices too. // 2) Dword dwStartPoint == Vertex to start rendering from. // 3) Dword dwNumVertices == The number of vertices to render. // 4) C3DPrimtiveType PrimType == The type of primitive rendreing that should take place. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Render(Byte byStage, Dword dwStartPoint, Dword dwNumVertices, C3DPrimitiveType PrimType) { //Don't forget the render stage //At this point, the vertices object should have upload its block of //vertices to the renderbank, thus any changes to the vertices block here //will occur as well in the renderbank. //Protect from null vertices. if(m_pVertices != NULL) { //Update the render properties. m_pVertices->byStage = byStage; m_pVertices->pt = PrimType; m_pVertices->dwStartRend = dwStartPoint; //Update the amount of vertices to be rendered. m_pVertices->dwNumRend = dwNumVertices; } else return C3DERR_NACREATE; //Updated 12/23/04 -- System now uses a direct access method to the //renderer through the CRSManager and the pipeline has been removed. if(g_pCRSManager != NULL) if(g_pCRSManager->m_pC3D != NULL) g_pCRSManager->m_pC3D->ProcessVertexBuffer(m_hCallback); else return C3DERR_CRSNOTDEFINED; else return C3DERR_CRSNOTDEFINED; //return errors: By default returns okay. return C3D_OK; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Render // Overridden: NA // Permission: Public // Date: 10/11/04 // Type: Common 3D System Management. // Desc: Performs a rendering of the vertex block based on the provided stage. // Parameters: // 1) Byte byStage == The stage to render the block of vertices too. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Render(Byte byStage) { if(m_pVertices != NULL) return Render(byStage, 0, m_pVertices->dwVertnum, C3DPT_TRIANGLELIST); else return C3DERR_NACREATE; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Render // Overridden: NA // Permission: Public // Date: 10/11/04 // Type: Common 3D System Management. // Desc: Performs a rendering of the vertex block based on the default settings which are as follows. // 1) The Render Stage is zero. // 2) The number of vertices to render is the entire block. // 3) The starting vertex is the first one. // 4) The rendering primitive is a triangle list. // Parameters: None // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Render() { if(m_pVertices != NULL) return Render(0, 0, m_pVertices->dwVertnum, C3DPT_TRIANGLELIST); else return C3DERR_NACREATE; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Hold [v2.2] // Overridden: NA // Permission: Public // Date: 4/28/05 // Type: Common 3D System Management. // Desc: The hold function prevents the C3DVertices object from updating the vertex data // until the hold is released. This is to help performance by not requesting a correction // to the renderer for every vertex, but for the entire block. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Hold(){m_bHold = true;} /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: ReleaseHold [v2.2] // Overridden: NA // Permission: Public // Date: 4/28/05 // Type: Common 3D System Management. // Desc: Releases the hold. // The hold function prevents the C3DVertices object from updating the vertex data // until the hold is released. This is to help performance by not requesting a correction // to the renderer for every vertex, but for the entire block. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::ReleaseHold() { //Release the hold. m_bHold = false; //Refresh the object. RefreshVertexBank(); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Vertex2f // Overridden: NA // Permission: Public // Date: 3/10/04 // Type: Common 3D System Management. // Desc: Creates a new vertex element in the pipeline upon the x & y axis. // Parameters: // 1) float x == location of vertex on x-axis. // 2) float y == location of vertex on y-axis. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Vertex2f(float x, float y) { return Vertex3f(x, y, 0.0f); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Vertex2f -- Overloaded // Overridden: NA // Permission: Public // Date: 3/10/04 // Type: Common 3D System Management. // Desc: Does not create a vertex, rather adjusts a current vertex listed in dwIndex. If the index // doesn't exist, will return an error code. // Parameters: // 1) Dword dwIndex == Index of vertex to be adjusted. // 2) float x == location of vertex on x-axis. // 3) float y == location of vertex on y-axis. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Vertex2f(Dword dwIndex, float x, float y) { return Vertex3f(dwIndex, x, y, 0.0f); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Vertex3f // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Creates a new vertex element in the pipeline upon the x, y & z axis. // Parameters: // 1) float x == location of vertex on x-axis. // 2) float y == location of vertex on y-axis. // 3) float z == location of vertex on z-axis. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Vertex3f(float x, float y, float z) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Update the current position. m_dwCurrVertPos++; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return C3DERR_OUTOFRNG; //If using RHW, use only RHW. if(m_pVertices->wUsage != 0) if(UG_CHKRHW(m_pVertices->wUsage)) return Vertex4f(x, y, z, 0); //Zero the members of the structure. ZeroVertexElement(pCurrElem, 0); //Set the vertex data. pCurrElem->v3.x = x; pCurrElem->v3.y = y; pCurrElem->v3.z = z; //Set usage. m_pVertices->wUsage |= UG_XYZ; return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Vertex3f [v2.2] -- Overloaded // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Does not create a vertex, rather adjusts a current vertex listed in dwIndex. If the index // doesn't exist, will return an error code. // Parameters: // 1) Dword dwIndex == Index of vertex to be adjusted. // 2) float x == location of vertex on x-axis. // 3) float y == location of vertex on y-axis. // 4) float z == location of vertex on z-axis. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Vertex3f(Dword dwIndex, float x, float y, float z) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(dwIndex)) == NULL) return C3DERR_OUTOFRNG; //If using RHW, use only RHW. if(m_pVertices->wUsage != 0) if(UG_CHKRHW(m_pVertices->wUsage)) return Vertex4f(dwIndex, x, y, z, 0); //Update. pCurrElem->v3.x = x; pCurrElem->v3.y = y; pCurrElem->v3.z = z; //Set Usage m_pVertices->wUsage |= UG_XYZ; //Refresh the vertex object. RefreshVertexBank(); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Vertex4f // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Creates a new vertex element in the pipeline upon the x, y & z axis and rhw component. // Parameters: // 1) float x == location of vertex on x-axis. // 2) float y == location of vertex on y-axis. // 3) float z == location of vertex on z-axis. // 4) float rhw == w-reciprocal value. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Vertex4f(float x, float y, float z, float rhw) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Update the current position. m_dwCurrVertPos++; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return C3DERR_OUTOFRNG; //If using XYZ, use only XYZ. if(m_pVertices->wUsage != 0) if(UG_CHKXYZ(m_pVertices->wUsage)) return Vertex3f(x, y, z); //Zero the members of the structure. ZeroVertexElement(pCurrElem, 1); //Set the vertex data. pCurrElem->v4.x = x; pCurrElem->v4.y = y; pCurrElem->v4.z = z; pCurrElem->v4.rhw = rhw; //Set Usage m_pVertices->wUsage |= UG_XYZRHW; return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Vertex4f [v2.2] -- Overloaded // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Does not create a vertex, rather adjusts a current vertex listed in dwIndex. If the index // doesn't exist, will return an error code. // Parameters: // 1) Dword dwIndex == Index of vertex to be adjusted. // 2) float x == location of vertex on x-axis. // 3) float y == location of vertex on y-axis. // 4) float z == location of vertex on z-axis. // 5) float rhw == w-reciprocal value. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Vertex4f(Dword dwIndex, float x, float y, float z, float rhw) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(dwIndex)) == NULL) return C3DERR_OUTOFRNG; //If using XYZ, use only XYZ. if(m_pVertices->wUsage != 0) if(UG_CHKXYZ(m_pVertices->wUsage)) return Vertex3f(dwIndex, x, y, z); //Update. pCurrElem->v4.x = x; pCurrElem->v4.y = y; pCurrElem->v4.z = z; pCurrElem->v4.rhw = rhw; //Set Usage m_pVertices->wUsage |= UG_XYZRHW; //Refresh the vertex object. RefreshVertexBank(); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Texture2f // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Sets the 2D texture coordinates. // Parameters: // 1) float x == location of texture on x-axis. // 2) float y == location of texture on y-axis. // 3) Byte byStage == Optional Parameter. This system refers to stages as a level of texture coordinates // being assigned. // Microsoft's usage of the term stages may or may not be similiar. // By default uses the first stage[0]. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Texture2f(float u, float v, Byte byStage) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return C3DERR_OUTOFRNG; //Protect the stage array by not allowing the user to //specify a stage that doesn't exist. if(byStage > MAXTEXTURES) byStage = MAXTEXTURES; pCurrElem->t[byStage].x = u; pCurrElem->t[byStage].y = v; //Set texture level. UG_SETTEX(m_pVertices->wUsage,(byStage+2)); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Texture2f [v2.2] -- Overloaded. // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Adjusts the texture coordinates of the specific element listed in parameter dwIndex. // Parameters: // 1) Dword dwIndex == Index of texture to be adjusted. // 2) float x == location of texture on x-axis. // 3) float y == location of texture on y-axis. // 4) Byte byStage == Optional Parameter. This system refers to stages as a level of texture coordinates // being assigned. // Microsoft's usage of the term stages may or may not be similiar. // By default uses the first stage[0]. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Texture2f(Dword dwIndex, float u, float v, Byte byStage) { //Locals PSC3DVertex pCurrElem = NULL; C3DRenderBankStates rbs; C3DERR err = C3D_OK; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(dwIndex)) == NULL) return C3DERR_OUTOFRNG; //Set the render state based on if textures hvae been used before or not. //Check the usage. //If the texture has a usage check the texture type. if(m_pVertices->wUsage != 0) { //If textures coordinates have been already assigned //then refresh the current vertices. //If the texture coordinates have not been updated //recreate the object so that it will have a proper //vertices structure. Failure to do this will result //in system crashes. if(UG_CHKTEX(m_pVertices->wUsage)) rbs = BSV_REFRESH; else rbs = BSV_UPDATE; } else //No usage, update the vertices. rbs = BSV_UPDATE; //Protect the stage array by not allowing the user to //specify a stage that doesn't exist. if(byStage > MAXTEXTURES) byStage = MAXTEXTURES; pCurrElem->t[byStage].x = u; pCurrElem->t[byStage].y = v; //Set texture level. UG_SETTEX(m_pVertices->wUsage,(byStage+2)); //Refresh the vertex object. RefreshVertexBank(rbs); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Normal -- Overloaded. // Overridden: NA // Permission: Public // Date: 12/19/04 // Type: Common 3D System Management. // Desc: Sets the coordinates for the normal of the current vertex in focus. // Parameters: // 1) float x == Location of the normal coordinate on the x-axis. // 2) float y == Location of the normal coordinate on the y-axis. // 3) float z == location of texture on y-axis. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Normal(float x, float y, float z) { //Locals PSC3DVertex pCurrElem = NULL; C3DERR err = C3D_OK; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return C3DERR_OUTOFRNG; pCurrElem->n.x = x; pCurrElem->n.y = y; pCurrElem->n.z = z; //Set texture level. m_pVertices->wUsage |= UG_NORMAL; return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Normal [v2.2] -- Overloaded. // Overridden: NA // Permission: Public // Date: 12/19/04 // Type: Common 3D System Management. // Desc: Sets the coordinates for the normal of the current vertex in focus. // Parameters: // 1) Dword dwIndex == Index of vertex to be adjusted. // 2) float x == Location of the normal coordinate on the x-axis. // 3) float y == Location of the normal coordinate on the y-axis. // 4) float z == location of texture on y-axis. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Normal(Dword dwIndex, float x, float y, float z) { //Locals C3DERR err = C3D_OK; PSC3DVertex ver = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((ver = ReturnVertexElement(dwIndex)) == NULL) return C3DERR_OUTOFRNG; ver->n.x = x; ver->n.y = y; ver->n.z = z; //Set texture level. m_pVertices->wUsage |= UG_NORMAL; //Refresh the vertex object. RefreshVertexBank(); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Diffuse // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Sets the diffuse color of the current vertex. // Parameters: // 1) Dword dwColor == color to set vertex. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Diffuse(Dword dwColor) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return C3DERR_OUTOFRNG; pCurrElem->dwDiffuse = dwColor; m_pVertices->wUsage |= UG_DIFFUSE; return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Diffuse [v2.2] -- Overloaded. // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Adjusts the diffuse color of the vertex specified in dwIndex. // Parameters: // 1) Dword dwIndex == Index of vertex to be adjusted. // 2) Dword dwColor == color to set vertex. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Diffuse(Dword dwIndex, Dword dwColor) { //Locals C3DERR err = C3D_OK; PSC3DVertex ver = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((ver = ReturnVertexElement(dwIndex)) == NULL) return C3DERR_OUTOFRNG; ver->dwDiffuse = dwColor; m_pVertices->wUsage |= UG_DIFFUSE; //Refresh the vertex object. RefreshVertexBank(); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Specular // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Sets the specular color of the current vertex. // Parameters: // 1) Dword dwColor == color to set vertex. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Specular(Dword dwColor) { //Locals C3DERR err = C3D_OK; PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return C3DERR_OUTOFRNG; pCurrElem->dwSpecular = dwColor; m_pVertices->wUsage |= UG_SPECULAR; return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Specular [v2.2] -- Overloaded. // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Adjusts the specular color of the vertex specified in dwIndex. // Parameters: // 1) Dword dwIndex == Index of vertex to be adjusted. // 2) Dword dwColor == color to set vertex. // Return value: // C3DERR == An error code returned by the C3DVertices, please review C3DTypes.h for more information on // each code status. // C3DERR_PIPENOINDEX == return if vertex has not been created. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DERR C3DVertices::Specular(Dword dwIndex, Dword dwColor) { //Locals PSC3DVertex ver = NULL; C3DERR err = C3D_OK; //Null check & creation check. if(m_pVertices == NULL) return C3DERR_NACREATE; if(m_pVertices->pVArray == NULL) return C3DERR_NACREATE; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((ver = ReturnVertexElement(dwIndex)) == NULL) return C3DERR_OUTOFRNG; ver->dwSpecular = dwColor; m_pVertices->wUsage |= UG_SPECULAR; //Refresh the vertex object. RefreshVertexBank(); return err; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Transform // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Sets the W or transform value. // Parameters: // 1) float fTransform == value to set the transform(rhw) property too. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Transform(float fTransform) { //Locals PSC3DVertex pCurrElem = NULL; //Null check & creation check. if(m_pVertices == NULL) return; if(m_pVertices->pVArray == NULL) return; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((pCurrElem = ReturnVertexElement(m_dwCurrVertPos)) == NULL) return; //If using XYZ, do not transform. if(UG_CHKXYZ(m_pVertices->wUsage)) return; pCurrElem->v4.rhw = fTransform; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: Transform [v2.2] -- Overloaded // Overridden: NA // Permission: Public // Date: 3/29/04 // Type: Common 3D System Management. // Desc: Transforms the vertex specified in dwIndex. // Parameters: // 1) Dword dwIndex == Index of vertex to be transformed. // 2) float fTransform == value to set the transform(rhw) property too. // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// void C3DVertices::Transform(Dword dwIndex, float fTransform) { //Locals PSC3DVertex ver = NULL; //Null check & creation check. if(m_pVertices == NULL) return; if(m_pVertices->pVArray == NULL) return; //Return a pointer to the vertex element. //If a range failure occurs, it is due to the current position //exceeding the currently allocated vertices table. if((ver = ReturnVertexElement(dwIndex)) == NULL) return; //If using XYZ, do not transform. if(UG_CHKXYZ(m_pVertices->wUsage)) return; ver->v4.rhw = fTransform; //Refresh the vertex object. RefreshVertexBank(); } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: ReturnVerticesAmount // Overridden: NA // Permission: Public // Date: 3/30/04 // Type: Common 3D System Management. // Desc: Return the amount of vertices in the pipeline. // Parameters: None // Return value: // Dword == The amount of vertices the pipeline is using. ////////////////////////////////////////////////////////////////////////////////////////////////////// Dword C3DVertices::ReturnVerticesAmount() { if(m_pVertices != NULL) return m_pVertices->dwVertnum; else return 0; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: GetVertex [v4] // Overridden: NA // Permission: Public // Date: 5/15/05 // Type: Common 3D System Management. // *Tested: 5/15/05 // Desc: Returns a pointer to the current vertex in the vertices table. // Parameters: None // Return value: // PSC3DVertex == A pointer to the current vertex. ////////////////////////////////////////////////////////////////////////////////////////////////////// PSC3DVertex C3DVertices::GetVertex() { //Return vertices if valid if(m_pVertices != NULL) return ReturnVertexElement(m_pVertices->dwVertnum-1); else return NULL; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVertices // Name: GetVertex [v4] // Overridden: NA // Permission: Public // Date: 5/15/05 // Type: Common 3D System Management. // *Tested: 5/15/05 // Desc: Returns a pointer to the vertex at dwIndex in the vertices table. // Parameters: // 1) Dword dwIndex == Index of vertex to retrieve. // Return value: // PSC3DVertex == A pointer to the specified vertex. ////////////////////////////////////////////////////////////////////////////////////////////////////// PSC3DVertex C3DVertices::GetVertex(Dword dwIndex) { //Return vertices if valid if(m_pVertices != NULL) return ReturnVertexElement(dwIndex); else return NULL; }